import { Col, Row } from 'antd'
import React from 'react'
import ProForm from '@ant-design/pro-form';
import styles from './index.less'
import FormItem from '../FormItem';
interface Params {
  area?: any[],
}
export const ruleType = (e: number, type?: number, time?: number) => {
  if (e == 1) {
    return '练习题完成度';
  } else if (e == 2) {
    return '直播/回放出勤率';
  } else if (e == 3) {
    return '对弈胜率';
  } else if (type == 1 && e == 4) {
    return '完成';
  } else if (e == 4 && type == 0) {
    return '未对弈'
  } else if (e == 4) {
    return '对弈数量';
  } else if (e == 5) {
    return '对局连败';
  } else if (e == 6) {
    return '对局连胜';
  } else if (e == 7) {
    return '累计失败'
  } else if (type == 1 && e == 8 && time == 1) {
    return '对弈'
  } else if (type == 1 && e == 8) {
    return '对局胜利'
  } else if (e == 8) {
    return '累计胜利'
  } else if (e == 9) {
    return '棋灵闯关完成'
  } else if (e == 10) {
    return "对弈胜率"
  } else if (e == 11 && type == 0) {
    return "未对弈预警"
  } else if (e == 11 && time == 2) {
    return "完成"
  } else if (e == 11 && time == 1) {
    return '对弈'
  } else if (e == 11) {
    return "对弈数量"
  } else if (e == 12) {
    return "对局连败"
  } else if (e == 13) {
    return "对局连胜"
  } else if (e == 14) {
    return "对局失败"
  } else if (e == 15) {
    return "对局胜利"
  } else if (e == 16) {
    return "悟空战力每提升"
  } else if (e == 17) {
    return '棋灵品级升至'
  }
  else {
    return;
  }
}
export const handleTime = (e: number, type?: number) => {
  if (e == 1 && type == 1) {
    return '小时'
  }
  if (e == 1) {
    return '小时内'
  } else if (e == 2) {
    return '天内'
  } else if (e == 3) {
    return '局内'
  } else {
    return;
  }
}
export default function Exercises(props: Params) {
  const { area } = props

  const content = area?.map((item) => {
    const { id, ruleType: rule, value, compareType } = item?.warningRole ?? {}
    console.log(value);

    const { id: iId } = item;
    const i = 555;
    const { id: comId, ruleType: comRule, timeLimit: comtimeLimit, timeUnit: comtimeUnit, value: comValue, compareType: compareType1 } = item?.completeRole ?? {}
    return {
      i: `${id}`, name: `${ruleType(rule) || ''}${compareType ? compareType == '1' ? '高于' : '低于' : ""}`, value: value || (value == "" && compareType == "1" ? "80" : rule == "9" ? '15' : '10'),
      ii: comId, val: comtimeLimit || 7,
      iii: `${comId}${i + 1}`, nextName: `${handleTime(comtimeUnit) || ''}${ruleType(comRule) || ''}${compareType1 ? compareType1 == 1 ? '高于' : '低于' : ""}`, value1: comValue || (comValue == "" && rule == "9" ? "15" : "50"),
      isEnable: `${item?.isEnable}`, iId: iId
    };
  })
  // const content = [
  //   { i: 'key1', name: '练习题完成度低于', value: "10", ii: 'key11', nextName: '练习题完成度高于', value1: "50", switch: "1" },
  //   { i: 'key2', name: '直播/回放出勤低于', value: "10", ii: 'key22', nextName: '直播/回放出勤高于', value1: "50", switch: "1" },
  //   { i: 'key3', name: '练习题完成度高于', value: "80", nextName: '', switch: "1" },
  //   { i: 'key4', name: '直播/回放出勤高于', value: "80", nextName: '', switch: "1" },

  // ]
  return (
    <div className={styles.exercises}>
      <div style={{ marginBottom: '10px' }}>课堂&练习题环节</div>
      <div style={{ overflow: 'auto' }} className={styles.title}>
        <Row style={{ textAlign: 'center', flexWrap: 'nowrap' }}>
          <Col className={styles.border_style} span={10}>预警规则</Col>
          <Col className={styles.border_style} span={10}>完成规则</Col>
          <Col className={styles.border_style} span={4}>启用状态</Col>
        </Row>
        <ProForm.Item
          className={styles.form_style}
        >
          {
            content?.map((item: any, index: any) => {
              return <FormItem iId={item?.iId} key={index} index={item?.i} name={item?.name} val={item?.val} index1={item?.ii} index2={item?.iii} nextname={item?.nextName} value={item?.value} value1={item?.value1} isEnable={item?.isEnable} />
            })
          }
        </ProForm.Item>
      </div>
    </div>
  )
}
